package com.xiaocikuai.smallchunks.controller.JTEController;

import com.alibaba.fastjson.JSONObject;
import com.xiaocikuai.smallchunks.entity.Transaction.Address;
import com.xiaocikuai.smallchunks.mapper.Transaction.TransactionMapper;
import com.yl.jms.sdk.JtExpressApi;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * 云路供应链科技有限公司 版权所有 © Copyright 2021
 *
 * @Description: 订单创建
 * @Author: xuyangyang
 * @Date: 2020/12/29 14:34
 */
@RestController
public class OrderSaveController {
    @Autowired
    private JtExpressApi jtExpressApi;

    @Resource
    private TransactionMapper transactionMapper;

    /**
     * 订单创建的接口地址
     */
    public static final String url = "http://test-openapi.jtexpress.com.cn/webopenplatformapi/api/order/addOrder";

    @GetMapping("/addOrder")
    public JSONObject addOrder(int aid,String orderId) throws IOException {
        Map<String, Object> map = new HashMap<>();
        Map<String, Object> sender = new HashMap<>();
        Map<String, Object> receiver = new HashMap<>();
        map.put("txlogisticId",orderId);//客户订单号（传客户自己系统的订单号）
        map.put("network","6539187");//合作网点编码（没有则不传）
        map.put("expressType","EZ");//快件类型：EZ(标准快递),TYD(兔优达)
        map.put("orderType","1");//订单类型（有客户编号为月结）1、 散客；2、月结；
        map.put("serviceType","01");//服务类型 ：02 门店寄件 ； 01 上门取件
        map.put("deliveryType","03");//派送类型： 06 代收点自提 05 快递柜自提 04 站点自提 03 派送上门
        map.put("goodsType","1");//支付方式：PP_PM("寄付月结"), CC_CASH("到付现结");
        map.put("weight","1");

        sender.put("name","狄仁杰");
        sender.put("mobile","12345678909");
        sender.put("phone","");
        sender.put("countryCode","CHN");
        sender.put("prov","山东省");
        sender.put("city","淄博");
        sender.put("area","沂源县");
        sender.put("address","E通世界园");
        map.put("sender",sender);

        Address address = transactionMapper.getAddressInfo(aid);
        receiver.put("name",address.getConsignee());
        receiver.put("mobile",address.getTelephone());
        receiver.put("phone","");
        receiver.put("countryCode","CHN");
        receiver.put("prov",address.getProv());
        receiver.put("city",address.getCity());
        receiver.put("area",address.getArea());
        receiver.put("address",address.getDelivery());
        map.put("receiver",receiver);
        JSONObject location = jtExpressApi.postByCustom(map,url);
        return location;
    }
}
